package com.sl.mes.db.service.bd;

import com.github.pagehelper.PageHelper;
import com.sl.mes.db.dao.BdMaterialMapper;
import com.sl.mes.db.itf.bd.IBdMaterial;
import com.sl.mes.db.vo.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BdMaterialService implements IBdMaterial {

    @Resource
    private BdMaterialMapper bdMaterialMapper;

    @Override
    public BdMaterial findByCode(String code3) {
        BdMaterialExample example=new BdMaterialExample();
        example.or().andCodeEqualTo(code3);
        return bdMaterialMapper.selectOneByExample(example);
    }

    /**
     * 查询所有物料
     * @param offset
     * @param limit
     * @return
     */
    @Override
    public List<BdMaterial> queryAll(Integer offset, Integer limit) {
        BdMaterialExample example = new BdMaterialExample();
        example.or().andDrEqualTo(0);
        PageHelper.startPage(offset, limit);
        return bdMaterialMapper.selectByExample(example);
    }

    /**
     * 根据pk_marbasclass分类所有物料
     * @param pk_marbasclass
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public List<BdMaterial> queayAllByClass(String pk_marbasclass, Integer pageNo, Integer pageSize) {
        BdMaterialExample example = new BdMaterialExample();
        BdMaterialExample.Criteria criteria = example.createCriteria();
        criteria.andPkMarbasclassEqualTo(pk_marbasclass);
        PageHelper.startPage(pageNo, pageSize);
        return bdMaterialMapper.selectByExample(example);
    }



    @Override
    public BdMaterial findById(String pk_material) {
        return bdMaterialMapper.selectByPrimaryKey(pk_material);
    }

    @Override
    public List<BdMaterial> selectDropType() {
        return bdMaterialMapper.selectDropType();
    }





}
